package com.example.leetdemo.plan1;

import org.springframework.util.StringUtils;

import java.util.Arrays;

public class Sword014 {

    public boolean checkInclusion(String s1, String s2) {
        int le = s1.length();
        int[] sa = new int[26];
        for (int i = 0; i < s1.length(); i++) {
            int c1 = s1.charAt(i) - 'a';
            sa[c1]++;
        }
        int[][] te = new int[s2.length() - s1.length() + 1][26];
        for (int i = 0; i < s2.length() - le + 1; i++) {
            int c1 = s2.charAt(i + le - 1) - 'a';
            if (i == 0) {
                for (int j = 0; j < s1.length(); j++) {
                    int c2 = s2.charAt(j) - 'a';
                    te[0][c2]++;
                }
            } else {
                int c2 = s2.charAt(i - 1) - 'a';
                te[i] = Arrays.copyOf(te[i - 1], 26);
                te[i][c2]--;
                te[i][c1]++;
            }
        }
        for (int i = 0; i < s2.length() - s1.length() + 1; i++) {
            boolean b = true;
            for (int j = 0; j < 26; j++) {
                if (sa[j] != te[i][j]) {
                    b = false;
                    break;
                }
            }
            if (b) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Sword014 sword014 = new Sword014();
        System.err.println(sword014.checkInclusion("ab", "baa"));
        int[] a = new int[] {1, 1};
        int[] b = new int[] {1, 1};
        System.err.println(Arrays.equals(a, b));
    }
}
